package view.admin;

import model.booking.Booking;
import model.manager.Manager;
import model.room.Room;
import view.financial.Financial;
import view.login.Login;
import view.room.RoomFrame;
import view.user.CheckIn;
import view.user.ConfirmCheckIn;
import view.user.ContinuationOfResidence;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectOutputStream;
import java.time.LocalDate;

/*
 * Created by JFormDesigner on Sat May 25 00:02:58 CST 2024
 */


/**
 * @author 孟晗
 */
public class Admin extends JFrame {
    public static boolean isTenant;
    private Manager manager;

    public Admin(Manager manager) {
        initComponents();

        RoomFrame room=new RoomFrame();
        panel1.add(room,"room");
        Financial financial=new Financial();
        panel1.add(financial,"financial");

        ContinuationOfResidence continuationOfResidence=new ContinuationOfResidence(manager);
        panel1.add(continuationOfResidence,"continuationOfResidence");
        CheckIn checkIn=new CheckIn(manager);
        panel1.add(checkIn,"checkIn");

    }

    private void button1(ActionEvent e) {
        // TODO add your code here
        CardLayout cl=(CardLayout)panel1.getLayout();
        cl.show(panel1,"room");
    }

    private void button2(ActionEvent e) {
        // TODO add your code here
        CardLayout cl=(CardLayout)panel1.getLayout();
        cl.show(panel1,"financial");
    }
    //续住按钮
    private void ContinuationResidenceButton(ActionEvent e) {
        // TODO add your code here

        //new ContinuationOfResidence(manager).setVisible(true);//打开续住页面
        CardLayout cl=(CardLayout)panel1.getLayout();
        cl.show(panel1,"continuationOfResidence");

    }
    //确认用户入住按钮
    private void ConfirmCheckInButton(ActionEvent e) {
        // TODO add your code here
        CardLayout cl=(CardLayout)panel1.getLayout();
        cl.show(panel1,"checkIn");
    }


    private void initComponents() {
        // JFormDesigner - Component initialization - DO NOT MODIFY  //GEN-BEGIN:initComponents  @formatter:off
        button1 = new JButton();
        panel1 = new JPanel();
        label1 = new JLabel();
        button3 = new JButton();
        button4 = new JButton();
        button5 = new JButton();

        //======== this ========
        var contentPane = getContentPane();

        //---- button1 ----
        button1.setText("\u623f\u95f4\u7ba1\u7406");
        button1.addActionListener(e -> button1(e));

        //======== panel1 ========
        {
            panel1.setLayout(new CardLayout());
        }

        //---- label1 ----
        label1.setText("          \u6b22\u8fce\u60a8\uff01");

        //---- button3 ----
        button3.setText("\u7528\u6237\u7eed\u4f4f");
        button3.addActionListener(e -> ContinuationResidenceButton(e));

        //---- button4 ----
        button4.setText("\u7528\u6237\u5165\u4f4f");
        button4.addActionListener(e -> ConfirmCheckInButton(e));

        //---- button5 ----
        button5.setText("\u9000\u51fa");
        button5.addActionListener(e -> button5(e));

        GroupLayout contentPaneLayout = new GroupLayout(contentPane);
        contentPane.setLayout(contentPaneLayout);
        contentPaneLayout.setHorizontalGroup(
            contentPaneLayout.createParallelGroup()
                .addGroup(contentPaneLayout.createSequentialGroup()
                    .addGap(14, 14, 14)
                    .addGroup(contentPaneLayout.createParallelGroup()
                        .addGroup(contentPaneLayout.createSequentialGroup()
                            .addGroup(contentPaneLayout.createParallelGroup()
                                .addComponent(label1, GroupLayout.Alignment.TRAILING, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addGroup(contentPaneLayout.createSequentialGroup()
                                    .addGroup(contentPaneLayout.createParallelGroup(GroupLayout.Alignment.TRAILING, false)
                                        .addComponent(button1, GroupLayout.Alignment.LEADING, GroupLayout.DEFAULT_SIZE, 100, Short.MAX_VALUE)
                                        .addComponent(button3, GroupLayout.Alignment.LEADING, GroupLayout.DEFAULT_SIZE, 100, Short.MAX_VALUE))
                                    .addGap(0, 19, Short.MAX_VALUE)))
                            .addGap(22, 22, 22))
                        .addGroup(contentPaneLayout.createSequentialGroup()
                            .addGroup(contentPaneLayout.createParallelGroup()
                                .addComponent(button5, GroupLayout.PREFERRED_SIZE, 100, GroupLayout.PREFERRED_SIZE)
                                .addComponent(button4, GroupLayout.PREFERRED_SIZE, 100, GroupLayout.PREFERRED_SIZE))
                            .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED, 41, Short.MAX_VALUE)))
                    .addComponent(panel1, GroupLayout.DEFAULT_SIZE, 457, Short.MAX_VALUE)
                    .addContainerGap())
        );
        contentPaneLayout.setVerticalGroup(
            contentPaneLayout.createParallelGroup()
                .addGroup(contentPaneLayout.createSequentialGroup()
                    .addGap(14, 14, 14)
                    .addComponent(label1, GroupLayout.PREFERRED_SIZE, 28, GroupLayout.PREFERRED_SIZE)
                    .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED)
                    .addComponent(button1, GroupLayout.PREFERRED_SIZE, 55, GroupLayout.PREFERRED_SIZE)
                    .addGap(18, 18, 18)
                    .addComponent(button3, GroupLayout.PREFERRED_SIZE, 55, GroupLayout.PREFERRED_SIZE)
                    .addGap(29, 29, 29)
                    .addComponent(button4, GroupLayout.PREFERRED_SIZE, 56, GroupLayout.PREFERRED_SIZE)
                    .addGap(28, 28, 28)
                    .addComponent(button5, GroupLayout.PREFERRED_SIZE, 56, GroupLayout.PREFERRED_SIZE)
                    .addContainerGap(68, Short.MAX_VALUE))
                .addGroup(contentPaneLayout.createSequentialGroup()
                    .addContainerGap()
                    .addComponent(panel1, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addContainerGap())
        );
        pack();
        setLocationRelativeTo(getOwner());
        // JFormDesigner - End of component initialization  //GEN-END:initComponents  @formatter:on
    }

    private void button5(ActionEvent e) {
        // TODO add your cowde here
        //保存房间信息
        String filename = "project/src/common/Rooms.txt";  //文件路径

        try (ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream(filename))) {
            out.writeObject(Room.getRooms());
        } catch (IOException e2) {
            e2.printStackTrace();
        }
        //退出
        new Login().setVisible(true);
        this.dispose();
    }

    // JFormDesigner - Variables declaration - DO NOT MODIFY  //GEN-BEGIN:variables  @formatter:off
    private JButton button1;
    private JPanel panel1;
    private JLabel label1;
    private JButton button3;
    private JButton button4;
    private JButton button5;
    // JFormDesigner - End of variables declaration  //GEN-END:variables  @formatter:on
}
